package com.zmc.dynamic.controller;

import com.alibaba.fastjson.JSON;
import com.zmc.dynamic.service.StudentService;
import com.zmc.dynamic.domain.Student;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping(value = "student/")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("save")
    public String save(){
        Student student = new Student();
        student.setCore(80);
        student.setName("李斯");
        studentService.save(student);
        return JSON.toJSONString(student);
    }

    @RequestMapping("update/{id}")
    public String update(@PathVariable("id") Long id){
        Student student = studentService.getById(id);
        studentService.updateById(student);
        return JSON.toJSONString(student);
    }

    @RequestMapping("get/{id}")
    public String get(@PathVariable("id") Long id){
        Student student = studentService.getById(id);
        return JSON.toJSONString(student);
    }

    @RequestMapping("delete/{id}")
    public String delete(@PathVariable("id") Long id){
        studentService.removeById(id);
        return "ok";
    }
}
